package com.qg.auth.util;

import com.qg.auth.handler.WebContextHandler;
import java.util.Map;

/**
 * @Author QG
 * @Date 2023/5/29 14:07
 * @description 全局上下文
 **/
public class WebContextUtil {


    /**
     * 获取用户信息
     * @param clazz
     * @return
     * @param <T>
     */
    public static <T> T getUserInfo(Class<T> clazz) {
        WebContextHandler webContextHandler = (WebContextHandler) WebBeanFactory.getBean("webContextHandler");
        T user = null;
        try {
            user = webContextHandler.getUser(clazz);
            return user;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static Map getUserInfo() {
        WebContextHandler webContextHandler = (WebContextHandler) WebBeanFactory.getBean("webContextHandler");
        Map user = null;
        try {
            user = webContextHandler.getUser();
            return user;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    /**
     * 设置用户信息
     * @param user
     */
    public static String setUserInfo(Object user) {
        WebContextHandler webContextHandler = (WebContextHandler) WebBeanFactory.getBean("webContextHandler");
        String key = webContextHandler.setUser(user);
        return key;
    }
}
